package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.MenuMapper;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.User;
import com.itheima.health.service.MenuService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Page pageData =null;
        //  条件构造器
        QueryWrapper<Menu> wrapper = new QueryWrapper<Menu>();
        //  1  mp  分页查询   完成分页查询   select  *  from   xxx  limit     count(1)
        if(StringUtils.isBlank(queryPageBean.getQueryString())){
            //  无条件分页
            //  page  结合 分页插件
            pageData   = page(new Page(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()));
        }else{
            wrapper.eq("name",queryPageBean.getQueryString());
            pageData   = page(new Page(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),wrapper);
        }
        // 2  结果集封装 PageResult返回
        PageResult pageResult = new PageResult(pageData.getTotal(),pageData.getRecords());
        return pageResult;
    }
}
